package yjl.spec.edu.week11_class023;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import yjl.spec.edu.week11_class023.R;

public class firstActivity extends AppCompatActivity {
    private List<First> listFirst = new ArrayList<First>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);

        initLisemesgs(); // 初始化数据

        FirstAdapter adapter = new FirstAdapter(firstActivity.this, R.layout.first_item, listFirst);
        ListView listView = (ListView) findViewById(R.id.list_view_wechat);

        listView.setAdapter(adapter);
        
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                First first = listFirst.get(position);
                Toast.makeText(firstActivity.this, first.getMesg(), Toast.LENGTH_SHORT).show();
            }
        });

    }
    private void initLisemesgs() {
        for (int i = 0; i < 2; i++) {
            First mesg1 = new First("订阅号消息","xxxxxxxxxxxxx",R.drawable.wechat13);
            listFirst.add(mesg1);
            First mesg2 = new First("指云端","xxxxxxxxxxxxx",R.drawable.wechat3);
            listFirst.add(mesg2);
            First mesg3 = new First("微信收款助手","xxxxxxxxxxxxx",R.drawable.wechat4);
            listFirst.add(mesg3);
            First mesg4 = new First("金大师为名服务","xxxxxxxxxxxxx",R.drawable.wechat5);
            listFirst.add(mesg4);
            First mesg5 = new First("春晖花园客户服务中心","xxxxxxxxxxxxx",R.drawable.wechat6);
            listFirst.add(mesg5);
            First mesg6 = new First("XXXXXXX","xxxxxxxxxxxxx",R.drawable.wechat7);
            listFirst.add(mesg6);
            First mesg7 = new First("微信团队","xxxxxxxxxxxxx",R.drawable.wechat8);
            listFirst.add(mesg7);
        }
    }
}
